package site.sorghum.ddl.solon.prop;


import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.noear.solon.annotation.Configuration;
import org.noear.solon.annotation.Init;
import org.noear.solon.annotation.Inject;
import org.springframework.boot.context.properties.ConfigurationProperties;
import site.sorghum.ddl.config.DdlGlobalConfig;

import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.List;

@Configuration
@org.springframework.context.annotation.Configuration
@ConfigurationProperties(prefix = "sorghum-ddl")
@Inject("${sorghum-ddl}")
@Slf4j
@Data
public class GlobalConfigProp {
    boolean init = false;

    @Init
    @PostConstruct
    public void init() {
        if (init) {
            return;
        }
        DdlGlobalConfig.basePackages = basePackages;
        DdlGlobalConfig.dropColumn = dropColumn;
        DdlGlobalConfig.createTable = createTable;
        DdlGlobalConfig.addIndex = addIndex;
        DdlGlobalConfig.addColumn = addColumn;
        DdlGlobalConfig.dropIndex = dropIndex;
        DdlGlobalConfig.banExe = banExe;
        DdlGlobalConfig.logPath = logPath;
        init = true;
        log.info("[Sorghum-DDL] 扫描包路径为:{}", basePackages);
    }

    /**
     * 扫描的包
     */
    public List<String> basePackages = new ArrayList<>();

    /**
     * 是否创建表
     */
    public boolean createTable = false;

    /**
     * 是否创建索引
     */
    public boolean addIndex = false;

    /**
     * 是否增加列
     */
    public boolean addColumn = false;

    /**
     * 是否删除列
     */
    public boolean dropColumn = false;

    /**
     * 是否删除索引
     */
    public boolean dropIndex = false;


    /**
     * 禁止所有执行
     */
    public boolean banExe = false;

    /**
     * 日志路径
     */
    public String logPath = "";
}
